<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>添加接口设计</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="../../component/ui/css/ui.css"/>
    </head>
    <body>
        <form class="layui-form" action="" lay-filter="editform">
            <div class="mainBox">
                <div class="main-container">
                    <div class="main-container">
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required|len" autocomplete="off" min="2" placeholder="请输入名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">唯一标志</label>
                            <div class="layui-input-block">
                                <input type="text" name="key" lay-verify="required|len" autocomplete="off" min="2" placeholder="请输入唯一标志" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属模块</label>
                            <div class="layui-input-block">
                                <input type="text" name="mod_key" lay-verify="required|len" autocomplete="off" readonly class="layui-input">
                            </div>
                        </div>
                       <div class="layui-form-item">
                            <label class="layui-form-label">接口方法</label>
                            <div class="layui-input-block">
                                <input type="radio" value="post" name="method" title="POST" checked>
                                <input type="radio" value="get" name="method" title="GET">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <div class="bottom">
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="api-save">
                        <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
                </div>
            </div>
        </form>
        <script src="../../config/config.js"></script>
        <script src="../../component/layui/layui.js"></script>
        <script src="../../component/ui/ui.js"></script>
        <script>
            layui.use([
                'form', 'layer', 'dropdown', 'iconSelectedPlus'
            ], function () {
                let form = layui.form,
                    layer = layui.layer,
                    $ = layui.$,
                    req = _req(),
                    dropdown = layui.dropdown,
                    iconSelectedPlus = layui.iconSelectedPlus;
                form.verify({
                    len: (val, item) => {
                        let min = item.getAttribute("min")
                        if (val.length < min) {
                            return '长度不能小于' + min;
                        }
                    }
                })
                 _get(layui, 'api/editBefore?id=' + req.id, res => {
                    form.val('editform',res)
                });
                //监听提交
                form.on('submit(api-save)', function (data) {
                    data = data.field;
                    data.id = req.id;
                    _post(layui, 'api/edit', data, res => {
                        //console.log(res)
                        parent
                            .layui
                            .table
                            .reload("api-table");
                        parent
                            .layer
                            .close(parent.layer.getFrameIndex(window.name)); //关闭当前页

                    })

                    return false;
                });

            });
        </script>

    </body>
</html>